{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号\n",
    "pd.set_option('max_columns', 100)  #最大展示特征列数量\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>DOB</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000026A10</td>\n",
       "      <td>Male</td>\n",
       "      <td>Dehradun</td>\n",
       "      <td>21500</td>\n",
       "      <td>03-Apr-87</td>\n",
       "      <td>05-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>APTARA INC</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>HBXC</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2649.39</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S122</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000054C40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Mumbai</td>\n",
       "      <td>42000</td>\n",
       "      <td>12-May-80</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ATUL LTD</td>\n",
       "      <td>Axis Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>8</td>\n",
       "      <td>HAXA</td>\n",
       "      <td>690000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>13800.0</td>\n",
       "      <td>19849.90</td>\n",
       "      <td>Y</td>\n",
       "      <td>Mobile</td>\n",
       "      <td>C</td>\n",
       "      <td>S133</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000066O10</td>\n",
       "      <td>Female</td>\n",
       "      <td>Jaipur</td>\n",
       "      <td>10000</td>\n",
       "      <td>19-Sep-89</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>SHAREKHAN PVT LTD</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>N</td>\n",
       "      <td>0</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S133</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000110G00</td>\n",
       "      <td>Female</td>\n",
       "      <td>Chennai</td>\n",
       "      <td>14650</td>\n",
       "      <td>15-Aug-91</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>MAERSK GLOBAL SERVICE CENTRES</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>N</td>\n",
       "      <td>0</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Mobile</td>\n",
       "      <td>C</td>\n",
       "      <td>S133</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000113J30</td>\n",
       "      <td>Male</td>\n",
       "      <td>Chennai</td>\n",
       "      <td>23400</td>\n",
       "      <td>22-Jul-87</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>SCHAWK</td>\n",
       "      <td>Axis Bank</td>\n",
       "      <td>Y</td>\n",
       "      <td>0</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S143</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender      City  Monthly_Income        DOB  \\\n",
       "0  ID000026A10    Male  Dehradun           21500  03-Apr-87   \n",
       "1  ID000054C40    Male    Mumbai           42000  12-May-80   \n",
       "2  ID000066O10  Female    Jaipur           10000  19-Sep-89   \n",
       "3  ID000110G00  Female   Chennai           14650  15-Aug-91   \n",
       "4  ID000113J30    Male   Chennai           23400  22-Jul-87   \n",
       "\n",
       "  Lead_Creation_Date  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "0          05-May-15             100000.0                  3.0           0.0   \n",
       "1          01-May-15                  0.0                  0.0           0.0   \n",
       "2          01-May-15             300000.0                  2.0           0.0   \n",
       "3          01-May-15                  0.0                  0.0           0.0   \n",
       "4          01-May-15             100000.0                  1.0        5000.0   \n",
       "\n",
       "                   Employer_Name Salary_Account Mobile_Verified  Var5  Var1  \\\n",
       "0                     APTARA INC     ICICI Bank               Y     3  HBXC   \n",
       "1                       ATUL LTD      Axis Bank               Y     8  HAXA   \n",
       "2              SHAREKHAN PVT LTD     ICICI Bank               N     0  HBXX   \n",
       "3  MAERSK GLOBAL SERVICE CENTRES      HDFC Bank               N     0  HBXX   \n",
       "4                         SCHAWK      Axis Bank               Y     0  HBXX   \n",
       "\n",
       "   Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0               100000.0                    3.0           20.0   \n",
       "1               690000.0                    5.0           24.0   \n",
       "2                    NaN                    NaN            NaN   \n",
       "3                    NaN                    NaN            NaN   \n",
       "4               100000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted Filled_Form  Device_Type Var2 Source  \\\n",
       "0          1000.0             2649.39           N  Web-browser    B   S122   \n",
       "1         13800.0            19849.90           Y       Mobile    C   S133   \n",
       "2             NaN                 NaN           N  Web-browser    B   S133   \n",
       "3             NaN                 NaN           N       Mobile    C   S133   \n",
       "4             NaN                 NaN           N  Web-browser    B   S143   \n",
       "\n",
       "   Var4  \n",
       "0     3  \n",
       "1     5  \n",
       "2     1  \n",
       "3     1  \n",
       "4     1  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取数据\n",
    "# path to where the data lies\n",
    "dpath = './data/'\n",
    "train = pd.read_csv(dpath +\"Test.csv\", encoding='utf-8')\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Var4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>3.771700e+04</td>\n",
       "      <td>3.767700e+04</td>\n",
       "      <td>37677.000000</td>\n",
       "      <td>37677.000000</td>\n",
       "      <td>37717.000000</td>\n",
       "      <td>2.279500e+04</td>\n",
       "      <td>22795.000000</td>\n",
       "      <td>12110.000000</td>\n",
       "      <td>11971.000000</td>\n",
       "      <td>12110.000000</td>\n",
       "      <td>37717.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>3.980311e+04</td>\n",
       "      <td>2.293886e+05</td>\n",
       "      <td>2.153887</td>\n",
       "      <td>3498.142270</td>\n",
       "      <td>4.972320</td>\n",
       "      <td>3.946479e+05</td>\n",
       "      <td>3.905111</td>\n",
       "      <td>19.261884</td>\n",
       "      <td>5108.995155</td>\n",
       "      <td>10943.676404</td>\n",
       "      <td>2.952303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.361382e+05</td>\n",
       "      <td>3.539572e+05</td>\n",
       "      <td>2.019334</td>\n",
       "      <td>9857.470897</td>\n",
       "      <td>5.668464</td>\n",
       "      <td>3.055262e+05</td>\n",
       "      <td>1.151386</td>\n",
       "      <td>5.874120</td>\n",
       "      <td>4741.974657</td>\n",
       "      <td>7360.757833</td>\n",
       "      <td>1.689596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.990000</td>\n",
       "      <td>250.000000</td>\n",
       "      <td>1176.410000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000e+05</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>6196.220000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3840.000000</td>\n",
       "      <td>9425.760000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3500.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>5.000000e+05</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>6250.000000</td>\n",
       "      <td>12840.030000</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>3.500000e+07</td>\n",
       "      <td>1.500000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>430000.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3.000000e+06</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>89552.030000</td>\n",
       "      <td>7.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "count    3.771700e+04         3.767700e+04         37677.000000   \n",
       "mean     3.980311e+04         2.293886e+05             2.153887   \n",
       "std      2.361382e+05         3.539572e+05             2.019334   \n",
       "min      0.000000e+00         0.000000e+00             0.000000   \n",
       "25%      1.650000e+04         0.000000e+00             0.000000   \n",
       "50%      2.500000e+04         1.000000e+05             2.000000   \n",
       "75%      4.000000e+04         3.000000e+05             4.000000   \n",
       "max      3.500000e+07         1.500000e+07            10.000000   \n",
       "\n",
       "        Existing_EMI          Var5  Loan_Amount_Submitted  \\\n",
       "count   37677.000000  37717.000000           2.279500e+04   \n",
       "mean     3498.142270      4.972320           3.946479e+05   \n",
       "std      9857.470897      5.668464           3.055262e+05   \n",
       "min         0.000000      0.000000           5.000000e+04   \n",
       "25%         0.000000      0.000000           2.000000e+05   \n",
       "50%         0.000000      2.000000           3.000000e+05   \n",
       "75%      3500.000000     11.000000           5.000000e+05   \n",
       "max    430000.000000     18.000000           3.000000e+06   \n",
       "\n",
       "       Loan_Tenure_Submitted  Interest_Rate  Processing_Fee  \\\n",
       "count           22795.000000   12110.000000    11971.000000   \n",
       "mean                3.905111      19.261884     5108.995155   \n",
       "std                 1.151386       5.874120     4741.974657   \n",
       "min                 1.000000      11.990000      250.000000   \n",
       "25%                 3.000000      15.000000     2000.000000   \n",
       "50%                 4.000000      18.000000     3840.000000   \n",
       "75%                 5.000000      20.000000     6250.000000   \n",
       "max                 6.000000      37.000000    50000.000000   \n",
       "\n",
       "       EMI_Loan_Submitted          Var4  \n",
       "count        12110.000000  37717.000000  \n",
       "mean         10943.676404      2.952303  \n",
       "std           7360.757833      1.689596  \n",
       "min           1176.410000      0.000000  \n",
       "25%           6196.220000      1.000000  \n",
       "50%           9425.760000      3.000000  \n",
       "75%          12840.030000      5.000000  \n",
       "max          89552.030000      7.000000  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 37717 entries, 0 to 37716\n",
      "Data columns (total 24 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   ID                     37717 non-null  object \n",
      " 1   Gender                 37717 non-null  object \n",
      " 2   City                   37319 non-null  object \n",
      " 3   Monthly_Income         37717 non-null  int64  \n",
      " 4   DOB                    37717 non-null  object \n",
      " 5   Lead_Creation_Date     37717 non-null  object \n",
      " 6   Loan_Amount_Applied    37677 non-null  float64\n",
      " 7   Loan_Tenure_Applied    37677 non-null  float64\n",
      " 8   Existing_EMI           37677 non-null  float64\n",
      " 9   Employer_Name          37675 non-null  object \n",
      " 10  Salary_Account         32680 non-null  object \n",
      " 11  Mobile_Verified        37717 non-null  object \n",
      " 12  Var5                   37717 non-null  int64  \n",
      " 13  Var1                   37717 non-null  object \n",
      " 14  Loan_Amount_Submitted  22795 non-null  float64\n",
      " 15  Loan_Tenure_Submitted  22795 non-null  float64\n",
      " 16  Interest_Rate          12110 non-null  float64\n",
      " 17  Processing_Fee         11971 non-null  float64\n",
      " 18  EMI_Loan_Submitted     12110 non-null  float64\n",
      " 19  Filled_Form            37717 non-null  object \n",
      " 20  Device_Type            37717 non-null  object \n",
      " 21  Var2                   37717 non-null  object \n",
      " 22  Source                 37717 non-null  object \n",
      " 23  Var4                   37717 non-null  int64  \n",
      "dtypes: float64(8), int64(3), object(13)\n",
      "memory usage: 6.9+ MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gender\n",
      "Index(['Male', 'Female'], dtype='object')\n",
      "City\n",
      "Index(['Dehradun', 'Mumbai', 'Jaipur', 'Chennai', 'Gurgaon', 'Bengaluru',\n",
      "       'Surat', 'Delhi', 'Tirupati', 'Ahmedabad',\n",
      "       ...\n",
      "       'Beawar', 'DWARKA', 'Beed', 'Kheda', 'Muktsar', 'Saiha', 'Shajapur',\n",
      "       'Dhubri', 'Morena', 'Karim Ganj'],\n",
      "      dtype='object', length=610)\n",
      "Salary_Account\n",
      "Index(['ICICI Bank', 'Axis Bank', 'HDFC Bank', 'State Bank of India',\n",
      "       'Karur Vysya Bank', 'Allahabad Bank', 'Syndicate Bank', 'Canara Bank',\n",
      "       'Union Bank of India', 'Kotak Bank', 'Bank of Baroda', 'IDBI Bank',\n",
      "       'Citibank', 'Oriental Bank of Commerce', 'United Bank of India',\n",
      "       'Federal Bank', 'Punjab National Bank', 'Bank of India', 'Andhra Bank',\n",
      "       'Yes Bank', 'Saraswat Bank', 'IndusInd Bank', 'Indian Overseas Bank',\n",
      "       'Standard Chartered Bank', 'UCO Bank', 'Bank of Maharasthra',\n",
      "       'Corporation bank', 'HSBC', 'South Indian Bank',\n",
      "       'Tamil Nadu Mercantile Bank', 'State Bank of Travancore',\n",
      "       'Central Bank of India', 'Catholic Syrian Bank', 'Karnataka Bank',\n",
      "       'Abhyuday Co-op Bank Ltd', 'Indian Bank', 'State Bank of Indore',\n",
      "       'State Bank of Mysore', 'ING Vysya', 'The Ratnakar Bank Ltd',\n",
      "       'J&K Bank', 'State Bank of Hyderabad', 'State Bank of Patiala',\n",
      "       'State Bank of Bikaner & Jaipur', 'Dhanalakshmi Bank Ltd',\n",
      "       'Deutsche Bank', 'Vijaya Bank', 'Dena Bank', 'Lakshmi Vilas bank',\n",
      "       'Punjab & Sind bank', 'Firstrand Bank Limited', 'India Bulls',\n",
      "       'Bank of Rajasthan', 'B N P Paribas', 'GIC Housing Finance Ltd',\n",
      "       'Industrial And Commercial Bank Of China Limited',\n",
      "       'Ahmedabad Mercantile Cooperative Bank'],\n",
      "      dtype='object')\n",
      "Mobile_Verified\n",
      "Index(['Y', 'N'], dtype='object')\n",
      "Var1\n",
      "Index(['HBXC', 'HAXA', 'HBXX', 'HBXD', 'HBXB', 'HBXH', 'HBXA', 'HAXB', 'HCXF',\n",
      "       'HAYT', 'HAXM', 'HVYS', 'HCYS', 'HAZD', 'HCXD', 'HAVC', 'HCXG', 'HAXC',\n",
      "       'HAXF'],\n",
      "      dtype='object')\n",
      "Filled_Form\n",
      "Index(['N', 'Y'], dtype='object')\n",
      "Device_Type\n",
      "Index(['Web-browser', 'Mobile'], dtype='object')\n",
      "Var2\n",
      "Index(['B', 'C', 'E', 'F', 'D', 'G', 'A'], dtype='object')\n",
      "Source\n",
      "Index(['S122', 'S133', 'S143', 'S134', 'S156', 'S159', 'S127', 'S151', 'S123',\n",
      "       'S137', 'S153', 'S144', 'S161', 'S124', 'S158', 'S162', 'S157', 'S142',\n",
      "       'S129', 'S141', 'S126', 'S150', 'S138', 'S131', 'S136', 'S139', 'S132',\n",
      "       'S155'],\n",
      "      dtype='object')\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>DOB</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000026A10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>21500</td>\n",
       "      <td>03-Apr-87</td>\n",
       "      <td>05-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>APTARA INC</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2649.39</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000054C40</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>42000</td>\n",
       "      <td>12-May-80</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ATUL LTD</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>690000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>13800.0</td>\n",
       "      <td>19849.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000066O10</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>10000</td>\n",
       "      <td>19-Sep-89</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>SHAREKHAN PVT LTD</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000110G00</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>14650</td>\n",
       "      <td>15-Aug-91</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>MAERSK GLOBAL SERVICE CENTRES</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000113J30</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>23400</td>\n",
       "      <td>22-Jul-87</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>SCHAWK</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender  City  Monthly_Income        DOB Lead_Creation_Date  \\\n",
       "0  ID000026A10       0     0           21500  03-Apr-87          05-May-15   \n",
       "1  ID000054C40       0     1           42000  12-May-80          01-May-15   \n",
       "2  ID000066O10       1     2           10000  19-Sep-89          01-May-15   \n",
       "3  ID000110G00       1     3           14650  15-Aug-91          01-May-15   \n",
       "4  ID000113J30       0     3           23400  22-Jul-87          01-May-15   \n",
       "\n",
       "   Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "0             100000.0                  3.0           0.0   \n",
       "1                  0.0                  0.0           0.0   \n",
       "2             300000.0                  2.0           0.0   \n",
       "3                  0.0                  0.0           0.0   \n",
       "4             100000.0                  1.0        5000.0   \n",
       "\n",
       "                   Employer_Name  Salary_Account  Mobile_Verified  Var5  Var1  \\\n",
       "0                     APTARA INC               0                0     3     0   \n",
       "1                       ATUL LTD               1                0     8     1   \n",
       "2              SHAREKHAN PVT LTD               0                1     0     2   \n",
       "3  MAERSK GLOBAL SERVICE CENTRES               2                1     0     2   \n",
       "4                         SCHAWK               1                0     0     2   \n",
       "\n",
       "   Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0               100000.0                    3.0           20.0   \n",
       "1               690000.0                    5.0           24.0   \n",
       "2                    NaN                    NaN            NaN   \n",
       "3                    NaN                    NaN            NaN   \n",
       "4               100000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0          1000.0             2649.39            0            0     0       0   \n",
       "1         13800.0            19849.90            1            1     1       1   \n",
       "2             NaN                 NaN            0            0     0       1   \n",
       "3             NaN                 NaN            0            1     1       1   \n",
       "4             NaN                 NaN            0            0     0       2   \n",
       "\n",
       "   Var4  \n",
       "0     3  \n",
       "1     5  \n",
       "2     1  \n",
       "3     1  \n",
       "4     1  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字符串 数字化\n",
    "for feature_name in ['Gender', 'City', 'Salary_Account', 'Mobile_Verified', 'Var1', 'Filled_Form', 'Device_Type', 'Var2', 'Source']:\n",
    "    train[feature_name], uniques  = pd.factorize(train[feature_name])\n",
    "    train[feature_name] = train[feature_name].astype(np.uint16)\n",
    "    print(feature_name)\n",
    "    print(uniques)\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>21500</td>\n",
       "      <td>05-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2649.39</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>42000</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>690000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>13800.0</td>\n",
       "      <td>19849.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>10000</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>14650</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>23400</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income Lead_Creation_Date  Loan_Amount_Applied  \\\n",
       "0       0     0           21500          05-May-15             100000.0   \n",
       "1       0     1           42000          01-May-15                  0.0   \n",
       "2       1     2           10000          01-May-15             300000.0   \n",
       "3       1     3           14650          01-May-15                  0.0   \n",
       "4       0     3           23400          01-May-15             100000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Salary_Account  Mobile_Verified  Var5  \\\n",
       "0                  3.0           0.0               0                0     3   \n",
       "1                  0.0           0.0               1                0     8   \n",
       "2                  2.0           0.0               0                1     0   \n",
       "3                  0.0           0.0               2                1     0   \n",
       "4                  1.0        5000.0               1                0     0   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0               100000.0                    3.0           20.0   \n",
       "1     1               690000.0                    5.0           24.0   \n",
       "2     2                    NaN                    NaN            NaN   \n",
       "3     2                    NaN                    NaN            NaN   \n",
       "4     2               100000.0                    2.0            NaN   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0          1000.0             2649.39            0            0     0       0   \n",
       "1         13800.0            19849.90            1            1     1       1   \n",
       "2             NaN                 NaN            0            0     0       1   \n",
       "3             NaN                 NaN            0            1     1       1   \n",
       "4             NaN                 NaN            0            0     0       2   \n",
       "\n",
       "   Var4  \n",
       "0     3  \n",
       "1     5  \n",
       "2     1  \n",
       "3     1  \n",
       "4     1  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = train.drop(['ID', 'Employer_Name', 'DOB'], axis=1)\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>21500</td>\n",
       "      <td>05-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2649.39</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>42000</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>690000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>13800.0</td>\n",
       "      <td>19849.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>10000</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>14650</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>23400</td>\n",
       "      <td>01-May-15</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income Lead_Creation_Date  Loan_Amount_Applied  \\\n",
       "0       0     0           21500          05-May-15             100000.0   \n",
       "1       0     1           42000          01-May-15                  0.0   \n",
       "2       1     2           10000          01-May-15             300000.0   \n",
       "3       1     3           14650          01-May-15                  0.0   \n",
       "4       0     3           23400          01-May-15             100000.0   \n",
       "\n",
       "   Loan_Tenure_Applied  Existing_EMI  Salary_Account  Mobile_Verified  Var5  \\\n",
       "0                  3.0           0.0               0                0     3   \n",
       "1                  0.0           0.0               1                0     8   \n",
       "2                  2.0           0.0               0                1     0   \n",
       "3                  0.0           0.0               2                1     0   \n",
       "4                  1.0        5000.0               1                0     0   \n",
       "\n",
       "   Var1  Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0     0               100000.0                    3.0           20.0   \n",
       "1     1               690000.0                    5.0           24.0   \n",
       "2     2                    0.0                    0.0            0.0   \n",
       "3     2                    0.0                    0.0            0.0   \n",
       "4     2               100000.0                    2.0            0.0   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0          1000.0             2649.39            0            0     0       0   \n",
       "1         13800.0            19849.90            1            1     1       1   \n",
       "2             0.0                0.00            0            0     0       1   \n",
       "3             0.0                0.00            0            1     1       1   \n",
       "4             0.0                0.00            0            0     0       2   \n",
       "\n",
       "   Var4  \n",
       "0     3  \n",
       "1     5  \n",
       "2     1  \n",
       "3     1  \n",
       "4     1  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#NaN的处理\n",
    "#19.EMI_Loan_Submitted -提交的EMI贷款金额（INR）\n",
    "train[[\"EMI_Loan_Submitted\"]] = train[[\"EMI_Loan_Submitted\"]].fillna(0)\n",
    "#18.Processing_Fee - 提交贷款的处理费（INR）\n",
    "train[[\"Processing_Fee\"]] = train[[\"Processing_Fee\"]].fillna(0)\n",
    "#17.Interest_Rate - 提交贷款金额的利率\n",
    "train[[\"Interest_Rate\"]] = train[[\"Interest_Rate\"]].fillna(0)\n",
    "#16.Loan_Tenure_Submitted - 提交的贷款期限（单位为年，在看到资格后修改和选择）\n",
    "train[[\"Loan_Tenure_Submitted\"]] = train[[\"Loan_Tenure_Submitted\"]].fillna(0)\n",
    "#7.Loan_Amount_Applied - 贷款申请请求金额（印度卢比，INR）\n",
    "train[[\"Loan_Amount_Applied\"]] = train[[\"Loan_Amount_Applied\"]].fillna(0)\n",
    "#8.Loan_Tenure_Applied - 贷款申请期限（单位为年） \n",
    "train[[\"Loan_Tenure_Applied\"]] = train[[\"Loan_Tenure_Applied\"]].fillna(0)\n",
    "#Existing_EMI -现有贷款的EMI（EMI：电子货币机构许可证）\n",
    "train[[\"Existing_EMI\"]] = train[[\"Existing_EMI\"]].fillna(0)\n",
    "#15.Loan_Amount_Submitted - 提交的贷款金额（在看到资格后修改和选择）\n",
    "train[[\"Loan_Amount_Submitted\"]] = train[[\"Loan_Amount_Submitted\"]].fillna(0)\n",
    "\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(np.any(train.isnull()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 37717 entries, 0 to 37716\n",
      "Data columns (total 21 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   Gender                 37717 non-null  uint16 \n",
      " 1   City                   37717 non-null  uint16 \n",
      " 2   Monthly_Income         37717 non-null  int64  \n",
      " 3   Lead_Creation_Date     37717 non-null  object \n",
      " 4   Loan_Amount_Applied    37717 non-null  float64\n",
      " 5   Loan_Tenure_Applied    37717 non-null  float64\n",
      " 6   Existing_EMI           37717 non-null  float64\n",
      " 7   Salary_Account         37717 non-null  uint16 \n",
      " 8   Mobile_Verified        37717 non-null  uint16 \n",
      " 9   Var5                   37717 non-null  int64  \n",
      " 10  Var1                   37717 non-null  uint16 \n",
      " 11  Loan_Amount_Submitted  37717 non-null  float64\n",
      " 12  Loan_Tenure_Submitted  37717 non-null  float64\n",
      " 13  Interest_Rate          37717 non-null  float64\n",
      " 14  Processing_Fee         37717 non-null  float64\n",
      " 15  EMI_Loan_Submitted     37717 non-null  float64\n",
      " 16  Filled_Form            37717 non-null  uint16 \n",
      " 17  Device_Type            37717 non-null  uint16 \n",
      " 18  Var2                   37717 non-null  uint16 \n",
      " 19  Source                 37717 non-null  uint16 \n",
      " 20  Var4                   37717 non-null  int64  \n",
      "dtypes: float64(8), int64(3), object(1), uint16(9)\n",
      "memory usage: 4.1+ MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Lead_Creation_Date_Month</th>\n",
       "      <th>Lead_Creation_Date_Season</th>\n",
       "      <th>Lead_Creation_Date_Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>21500</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2649.39</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>42000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>690000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>13800.0</td>\n",
       "      <td>19849.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>10000</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>14650</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>23400</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>100000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender  City  Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "0       0     0           21500             100000.0                  3.0   \n",
       "1       0     1           42000                  0.0                  0.0   \n",
       "2       1     2           10000             300000.0                  2.0   \n",
       "3       1     3           14650                  0.0                  0.0   \n",
       "4       0     3           23400             100000.0                  1.0   \n",
       "\n",
       "   Existing_EMI  Salary_Account  Mobile_Verified  Var5  Var1  \\\n",
       "0           0.0               0                0     3     0   \n",
       "1           0.0               1                0     8     1   \n",
       "2           0.0               0                1     0     2   \n",
       "3           0.0               2                1     0     2   \n",
       "4        5000.0               1                0     0     2   \n",
       "\n",
       "   Loan_Amount_Submitted  Loan_Tenure_Submitted  Interest_Rate  \\\n",
       "0               100000.0                    3.0           20.0   \n",
       "1               690000.0                    5.0           24.0   \n",
       "2                    0.0                    0.0            0.0   \n",
       "3                    0.0                    0.0            0.0   \n",
       "4               100000.0                    2.0            0.0   \n",
       "\n",
       "   Processing_Fee  EMI_Loan_Submitted  Filled_Form  Device_Type  Var2  Source  \\\n",
       "0          1000.0             2649.39            0            0     0       0   \n",
       "1         13800.0            19849.90            1            1     1       1   \n",
       "2             0.0                0.00            0            0     0       1   \n",
       "3             0.0                0.00            0            1     1       1   \n",
       "4             0.0                0.00            0            0     0       2   \n",
       "\n",
       "   Var4  Lead_Creation_Date_Month  Lead_Creation_Date_Season  \\\n",
       "0     3                         4                          1   \n",
       "1     5                         4                          1   \n",
       "2     1                         4                          1   \n",
       "3     1                         4                          1   \n",
       "4     1                         4                          1   \n",
       "\n",
       "   Lead_Creation_Date_Year  \n",
       "0                       15  \n",
       "1                       15  \n",
       "2                       15  \n",
       "3                       15  \n",
       "4                       15  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#新增特征列  Lead_Creation_Date转化成月份 年份 季度 然后干掉Lead_Creation_Date列\n",
    "train['Lead_Creation_Date_Month'] = 0\n",
    "train['Lead_Creation_Date_Season'] = 0\n",
    "train['Lead_Creation_Date_Year'] = 0\n",
    "\n",
    "def handle_Lead_Creation_Date_month(x):\n",
    "    month_dict = {\n",
    "        'Jan':0,\n",
    "        'Feb':1,\n",
    "        'Mar':2,\n",
    "        'Apr':3,\n",
    "        'May':4,\n",
    "        'Jun':5,\n",
    "        'Jul':6,\n",
    "        'Aug':7,\n",
    "        'Sep':8,\n",
    "        'Oct':9,\n",
    "        'Nov':10,\n",
    "        'Dec':11,\n",
    "    }\n",
    "    date_data = x.split('-')\n",
    "    return month_dict[date_data[1]]\n",
    "\n",
    "def handle_Lead_Creation_Date_season(x):\n",
    "    month_dict = {\n",
    "        'Jan':0,\n",
    "        'Feb':0,\n",
    "        'Mar':0,\n",
    "        'Apr':1,\n",
    "        'May':1,\n",
    "        'Jun':1,\n",
    "        'Jul':2,\n",
    "        'Aug':2,\n",
    "        'Sep':2,\n",
    "        'Oct':3,\n",
    "        'Nov':3,\n",
    "        'Dec':3,\n",
    "    }\n",
    "    date_data = x.split('-')\n",
    "    return month_dict[date_data[1]]\n",
    "\n",
    "def handle_Lead_Creation_Date_year(x):\n",
    "    date_data = x.split('-')\n",
    "    return int(date_data[2])\n",
    "\n",
    "train['Lead_Creation_Date_Month'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_month(x), 0).astype(np.int64)\n",
    "train['Lead_Creation_Date_Season'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_season(x), 0).astype(np.int64)\n",
    "train['Lead_Creation_Date_Year'] = train['Lead_Creation_Date'].apply(lambda x: handle_Lead_Creation_Date_year(x), 0).astype(np.int64)\n",
    "\n",
    "\n",
    "train = train.drop(['Lead_Creation_Date'], axis=1)\n",
    "\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 37717 entries, 0 to 37716\n",
      "Data columns (total 23 columns):\n",
      " #   Column                     Non-Null Count  Dtype  \n",
      "---  ------                     --------------  -----  \n",
      " 0   Gender                     37717 non-null  uint16 \n",
      " 1   City                       37717 non-null  uint16 \n",
      " 2   Monthly_Income             37717 non-null  int64  \n",
      " 3   Loan_Amount_Applied        37717 non-null  float64\n",
      " 4   Loan_Tenure_Applied        37717 non-null  float64\n",
      " 5   Existing_EMI               37717 non-null  float64\n",
      " 6   Salary_Account             37717 non-null  uint16 \n",
      " 7   Mobile_Verified            37717 non-null  uint16 \n",
      " 8   Var5                       37717 non-null  int64  \n",
      " 9   Var1                       37717 non-null  uint16 \n",
      " 10  Loan_Amount_Submitted      37717 non-null  float64\n",
      " 11  Loan_Tenure_Submitted      37717 non-null  float64\n",
      " 12  Interest_Rate              37717 non-null  float64\n",
      " 13  Processing_Fee             37717 non-null  float64\n",
      " 14  EMI_Loan_Submitted         37717 non-null  float64\n",
      " 15  Filled_Form                37717 non-null  uint16 \n",
      " 16  Device_Type                37717 non-null  uint16 \n",
      " 17  Var2                       37717 non-null  uint16 \n",
      " 18  Source                     37717 non-null  uint16 \n",
      " 19  Var4                       37717 non-null  int64  \n",
      " 20  Lead_Creation_Date_Month   37717 non-null  int64  \n",
      " 21  Lead_Creation_Date_Season  37717 non-null  int64  \n",
      " 22  Lead_Creation_Date_Year    37717 non-null  int64  \n",
      "dtypes: float64(8), int64(6), uint16(9)\n",
      "memory usage: 4.7 MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "train.to_csv(dpath +'Bank_FE_test_org.csv',index=False,header=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
